cmake_minimum_required(VERSION 3.0)
project(qtch)
include(CMake/utils.cmake)
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finput-charset=UTF-8  -fexec-charset=UTF-8")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finput-charset=UTF-8  -fexec-charset=UTF-8")


include_directories(${PROJECT_SOURCE_DIR})


link_directories(/usr/lib/x86_64-linux-gnu/)
find_package(OpenSSL REQUIRED)
find_package(Boost 1.71  COMPONENTS regex REQUIRED)
find_package (PostgreSQL REQUIRED)
if(OPENSSL_FOUND)
    include_directories(${OPENSSL_INCLUDE_DIR})
endif()

if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIR})
    # link_directories("/usr/include/boost/regex/")
    message(STATUS "找到Boost:" ${Boost_INCLUDE_DIR} )
    message(STATUS "找到Boost link dir:" ${BOOST_LINK_DIR})
    message(STATUS "-Boost lib:" ${Boost_LIBRARIES} )
endif()

if(PostgreSQL_FOUND)
message(STATUS "找到PostgreSQL:" ${PostgreSQL_INCLUDE_DIR} )
include_directories(${PostgreSQL_INCLUDE_DIR})
message(STATUS "找到PostgreSQL:" ${PostgreSQL_LIBRARIES} )
endif()

find_package(jsoncpp REQUIRED)
if(jsoncpp_FOUND)
    set(JSONCPP_INCLUDE_DIR "/usr/include/jsoncpp")
    if(EXISTS "${JSONCPP_INCLUDE_DIR}")
	include_directories(${JSONCPP_INCLUDE_DIR})
	message(STATUS "find jsoncpp:" ${JSONCPP_INCLUDE_DIR} )
    endif()
endif()


set(
    LIB_SRC
    qtch/address.cc
    qtch/application.cc
    qtch/bytearray.cc
    qtch/config.cc
    qtch/daemon.cc
    qtch/email/email.cc
    qtch/email/smtp.cc
    qtch/env.cc
    qtch/db/postgresql.cc
    qtch/db/sqlite.cc
    qtch/fd_manage.cc
    qtch/fiber.cc
    qtch/hook.cc
    qtch/http/http.cc
    qtch/http/http_connection.cc
    qtch/http/http_parser.cc
    qtch/http/http_server.cc
    qtch/http/http_session.cc
    qtch/http/servlet.cc
    qtch/http/session_data.cc
    qtch/iomanager.cc
    qtch/infoPush/wecom_pusher.cc
    qtch/infoPush/WXBizMsgCrypt.cc
    qtch/library.cc
    qtch/log.cc
    qtch/module.cc
    qtch/mutex.cc
    qtch/scheduler.cc
    qtch/socket.cc
    qtch/stream.cc
    qtch/streams/socket_stream.cc
    qtch/tcp_server.cc
    qtch/thread.cc
    qtch/timer.cc
    qtch/tinyxml2.cc
    qtch/util.cc
    qtch/worker.cc
)

ragelmaker(qtch/http/httpclient_parser.rl LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/qtch/http)
ragelmaker(qtch/http/http11_parser.rl LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/qtch/http)
ragelmaker(qtch/uri.rl LIB_SRC ${CMAKE_CURRENT_SOURCE_DIR}/qtch)













add_library(qtch SHARED ${LIB_SRC})



set(
    LIBS
    qtch
    yaml-cpp
    pthread
    dl
    jsoncpp
    sqlite3
    ${PostgreSQL_LIBRARIES}
    ${OPENSSL_LIBRARIES}
    ${Boost_LIBRARIES}
)

set(
    ORM_SRCS
    qtch/orm/column.cc
    qtch/orm/index.cc
    qtch/orm/label.cc
    qtch/orm/orm.cc
    qtch/orm/ormParameter.cc
    qtch/orm/select.cc
    qtch/orm/table.cc
    qtch/orm/util.cc
    qtch/orm/delete.cc
    qtch/orm/update.cc
    qtch/orm/insert.cc
)

qtch_add_executable(orm "${ORM_SRCS}" qtch "${LIBS}")


qtch_add_executable(test_log "tests/test_log.cc" qtch "${LIBS}")
qtch_add_executable(test_config "tests/test_config.cc" qtch "${LIBS}")
qtch_add_executable(test_thread "tests/test_thread.cc" qtch "${LIBS}")
qtch_add_executable(test_fiber "tests/test_fiber.cc" qtch "${LIBS}")
qtch_add_executable(test_scheduler "tests/test_scheduler.cc" qtch "${LIBS}")
qtch_add_executable(test_iomanager "tests/test_iomanager.cc" qtch "${LIBS}")
qtch_add_executable(test_hook "tests/test_hook.cc" qtch "${LIBS}")
qtch_add_executable(test_address "tests/test_address.cc" qtch "${LIBS}")
qtch_add_executable(test_socket "tests/test_socket.cc" qtch "${LIBS}")
qtch_add_executable(test_bytearray "tests/test_bytearray.cc" qtch "${LIBS}")
qtch_add_executable(test_http "tests/test_http.cc" qtch "${LIBS}")
qtch_add_executable(test_http_parser "tests/test_http_parser.cc" qtch "${LIBS}")
qtch_add_executable(test_tcp_server "tests/test_tcp_server.cc" qtch "${LIBS}")
qtch_add_executable(test_http_server "tests/test_http_server.cc" qtch "${LIBS}")
qtch_add_executable(test_daemon "tests/test_daemon.cc" qtch "${LIBS}")
qtch_add_executable(test_env "tests/test_env.cc" qtch "${LIBS}")
qtch_add_executable(test_application "tests/test_application.cc" qtch "${LIBS}")
qtch_add_executable(test_util "tests/test_util.cc" qtch "${LIBS}")
qtch_add_executable(test_httpconnection "tests/test_httpconnection.cc" qtch "${LIBS}")
qtch_add_executable(test_wecom "tests/test_wecom.cc" qtch "${LIBS}")
qtch_add_executable(test_sqlite3 "tests/test_sqlite3.cc" qtch "${LIBS}")
qtch_add_executable(test_email "tests/test_email.cc" qtch "${LIBS}")
qtch_add_executable(test_Cypher "tests/test_Cypher.cc" qtch "${LIBS}")
qtch_add_executable(test_logFilePath "tests/test_logFilePath.cc" qtch "${LIBS}")


qtch_add_executable(test_socket_server "tests/test_socket_server.cc" qtch "${LIBS}")
qtch_add_executable(test_tinyxml2 "tests/test_tinyxml2.cc" qtch "${LIBS}")






add_library(test_module SHARED tests/test_module.cc)



set(
    TEST_ORM_LIBS
    ${LIBS}
    orm_data
)
    
set(
    TEST_ORM_DEPENDS
    qtch
    orm_data
)
    
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/orm_out)
# qtch_add_executable(test_orm "tests/test_orm.cc" "${TEST_ORM_DEPENDS}" "${TEST_ORM_LIBS}")


SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
